﻿Imports System.Security.Cryptography
Imports System.Collections.Generic
Imports System.Data
Imports System.IO
Imports System.Net
Namespace My



    ' 以下事件可用于 MyApplication:
    ' 
    ' Startup: 应用程序启动时在创建启动窗体之前引发。
    ' Shutdown: 在关闭所有应用程序窗体后引发。如果应用程序异常终止，则不会引发此事件。
    ' UnhandledException: 在应用程序遇到未处理的异常时引发。
    ' StartupNextInstance: 在启动单实例应用程序且应用程序已处于活动状态时引发。
    ' NetworkAvailabilityChanged: 在连接或断开网络连接时引发。
    Partial Friend Class MyApplication
        Private StrCollection As New List(Of String) '与网络数据连接
        Private StrDatetime As New List(Of DateTime)
        Private mGetNettime As DateTime


        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup


            ''网络下载地址
            'Dim Urlstrs As New List(Of String)
            'Urlstrs.Add("http://www.eia65.com/index.php?option=com_product&lid=6&Itemid=28")
            'Urlstrs.Add("http://www.era65.com/index.php?option=com_product&lid=6&Itemid=28")
            'Urlstrs.Add("http://sjzwrj.vip4.eshimai.com/index.php?option=com_product&lid=6&Itemid=28")

            'Dim mStr As String = "http://www.eia65.com/UserManage/AutoUpdater.xml" '版本文件
            Dim frm As New frmUpdateNet
            frm.DoCompareVersion()


            '是否是正式版
#Const NOISEVALUE = "正式版"

            '是否启用网络验证，否则是加密狗验证
#Const UseNetwork = True



            '小付修改的代码

            '是否是试用版本
            Dim bTryVersion As Boolean = True

#If NOISEVALUE = "试用版" Then
            bTryVersion = True
#Else

                            bTryVersion =False 

#End If


            '是否使用网络验证的方法，否则使用加密狗验证
            Dim bUseNetworkCheck As Boolean = True

#If UseNetwork Then
            bUseNetworkCheck = True

#Else
                                    bUseNetworkCheck = False

#End If



            Dim bReadyForUse As Boolean = False

            If bUseNetworkCheck Then

                Dim network As New NetWorkCheck()
                bReadyForUse = network.DoNetWorkCheck(bTryVersion)

            Else


                Dim usb As New UsbCheck

                If usb.DoCheck() Then
                    bReadyForUse = True
                End If



            End If



            If bReadyForUse = False Then

                End

            End If















            ''新版本下载访问  
            'Dim mVersion As String = Mid(My.Application.Info.Version.ToString, 1, 5)
            'Dim mNetVersion As String = GetTheLastUpdateVersion("http://www.eia65.com/UserManage/AutoUpdater.xml")
            'Dim MidNetVersion As String = Mid(mNetVersion, 1, 5)
            'Dim Urlstrs As New List(Of String)
            'Urlstrs.Add("http://www.eia65.com/index.php?option=com_product&lid=6&Itemid=28")
            'Urlstrs.Add("http://www.era65.com/index.php?option=com_product&lid=6&Itemid=28")
            'Urlstrs.Add("http://sjzwrj.vip4.eshimai.com/index.php?option=com_product&lid=6&Itemid=28")
            'If mVersion <> MidNetVersion Then
            '    If mNetVersion.Trim = "" Then
            '    Else
            '        If MsgBox("本程序已更新到 " & mNetVersion & " 版本,请到 http://www.eia65.com 下载新版本程序,是否关闭本程序并进行下载更新!", MsgBoxStyle.YesNo, "提示") = MsgBoxResult.Yes Then
            '            Dim Req As WebRequest
            '            Dim Resp As WebResponse
            '            For i As Integer = 0 To Urlstrs.Count - 1
            '                Dim url As New Uri(Urlstrs.Item(i)) '定义一个URI
            '                Req = WebRequest.Create(url)
            '                '试探N个网站的连接
            '                Try
            '                    Resp = Req.GetResponse '获得一个响应
            '                    System.Diagnostics.Process.Start(Urlstrs.Item(i))
            '                    Exit For
            '                Catch ex As Exception
            '                End Try
            '            Next
            '            End
            '        End If
            '    End If
            'End If

            ''验证
            'Dim mNetUrl As New List(Of String)
            'mNetUrl.Add("http://www.eia65.com/UserManage/User.txt")
            'mNetUrl.Add("http://www.era65.com/UserManage/User.txt")
            'mNetUrl.Add("http://sjzwrj.vip4.eshimai.com/UserManage/User.txt")
            'If TestFile(GetStrReslut(mNetUrl)) = False Then
            '    Dim frma As New frmLogo
            '    frma.mArryS = StrCollection
            '    frma.mDatetime = StrDatetime
            '    frma.mNetTime = mGetNettime
            '    If frma.ShowDialog = Windows.Forms.DialogResult.OK Then

            '    Else
            '        End
            '    End If
            'End If
        End Sub


        '''' <summary>
        '''' 获得相应的网络数据
        '''' </summary>
        '''' <remarks></remarks>
        'Public Function GetStrReslut(ByVal Urlstrs As List(Of String)) As List(Of String)
        '    Dim Req As WebRequest
        '    Dim Str As String = ""
        '    Dim mArry As New List(Of String)
        '    Dim Resp As WebResponse
        '    'Dim mGetResponse As Boolean = False '是否得到网络回应标记
        '    Try
        '        For i As Integer = 0 To Urlstrs.Count - 1
        '            Dim url As New Uri(Urlstrs.Item(i)) '定义一个URI
        '            Req = WebRequest.Create(url)
        '            '试探N个网站的连接
        '            Try
        '                Resp = Req.GetResponse '获得一个响应
        '                Exit For
        '            Catch ex As Exception
        '            End Try
        '        Next
        '        Dim netStream As StreamReader
        '        netStream = New StreamReader(Resp.GetResponseStream)
        '        Str = netStream.ReadToEnd.ToString
        '        Try
        '            For i As Integer = 0 To GetStringNumber(Str) / 5 - 1
        '                mArry.Add(GetString(Str, (i + 1) * 5).Trim)
        '                StrCollection.Add(mArry.Item(i))
        '                StrDatetime.Add(GetString(Str, (i + 1) * 5 - 1).Trim)
        '            Next
        '        Catch ex As Exception
        '            MsgBox("获取数据错误,请写相关人员联系!", MsgBoxStyle.OkOnly, "提示")
        '        End Try
        '    Catch exc As Exception
        '        MsgBox("网络连接异常", MsgBoxStyle.OkOnly, "提示")
        '    End Try
        '    Return mArry
        'End Function

        '''' <summary>
        '''' 检测验证文件
        '''' </summary>
        '''' <param name="mArryStr"></param>
        '''' <returns></returns>
        '''' <remarks></remarks>
        'Private Function TestFile(ByVal mArryStr As List(Of String)) As Boolean
        '    Try
        '        mGetNettime = GetInternetDateTime()
        '    Catch ex As Exception
        '        If MsgBox("网络连接异常,是否确定重试!", MsgBoxStyle.OkCancel, "提示") = MsgBoxResult.Ok Then
        '            Try
        '                mGetNettime = GetInternetDateTime()
        '            Catch exc As Exception
        '                If MsgBox("网络连接异常,是否确定重试!", MsgBoxStyle.OkCancel, "提示") = MsgBoxResult.Ok Then
        '                    Try
        '                        mGetNettime = GetInternetDateTime()
        '                    Catch exac As Exception
        '                        MsgBox("没有网络程序将进行关闭!", MsgBoxStyle.OkOnly, "提示")
        '                        End
        '                        Exit Function
        '                    End Try
        '                Else
        '                    End
        '                End If
        '            End Try
        '        Else
        '            End
        '        End If
        '    End Try

        '    If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\User.txt") Then
        '        FileOpen(1, My.Application.Info.DirectoryPath & "\User.txt", OpenMode.Input)
        '        '读取文件信息
        '        Dim Str As String = ""
        '        Do Until EOF(1)
        '            Str = LineInput(1)
        '            If Str.Trim <> "" Then
        '                Exit Do
        '            End If
        '        Loop
        '        FileClose(1)
        '        '验证数据
        '        Dim b As Boolean = False
        '        For i As Integer = 0 To mArryStr.Count - 1
        '            If Str = mArryStr.Item(i) Then
        '                If mGetNettime >= StrDatetime.Item(i) Then
        '                    MsgBox("您的软件使用时间已到期,请与作者联系!", MsgBoxStyle.OkOnly, "提示")
        '                    Exit For
        '                ElseIf StrDatetime.Item(i).Year - mGetNettime.Year = 0 And mGetNettime <= StrDatetime.Item(i) And StrDatetime.Item(i).Month - mGetNettime.Month = 0 And StrDatetime.Item(i).Day - mGetNettime.Day <= 7 Then
        '                    MsgBox("您的软件使用时间还有" & StrDatetime.Item(i).Day - mGetNettime.Day & "天,请与作者联系!", MsgBoxStyle.OkOnly, "提示")
        '                    b = True
        '                    Exit For
        '                Else
        '                    b = True
        '                    Exit For
        '                End If
        '            Else
        '                b = False
        '            End If
        '        Next
        '        If b = True Then
        '            Return True
        '        Else
        '            Return False
        '        End If
        '    Else
        '        Return False
        '    End If
        'End Function
    End Class
End Namespace

